package data_service

import (
	"errors"

	"gitee.com/gldmmhh/bbs/data_access"
)

func GetUserPosts(userId int64, page, size int) ([]data_access.Post, int64, error) {
	return data_access.GetPostsByUserId(userId, page, size)
}

func GetUserInfo(userId int64) (*data_access.User, error) {
	return data_access.GetUserById(userId)
}

func GetUserByUserName(username string) (*data_access.User, error) {
	user, err := data_access.GetUserByUserName(username)
	if err != nil {
		return nil, err
	}
	return user, nil
}

func Register(username, password string) (*data_access.User, error) {
	return data_access.Register(username, password)
}

func GetFollowingList(userId int64, page, size int) ([]data_access.User, int64, error) {
	return data_access.GetFollowingList(userId, page, size)
}

func FollowUser(userId, followerId int64) error {
	isFollowing, err := data_access.IsFollowing(userId, followerId)
	if err != nil {
		return err
	}
	if isFollowing {
		return errors.New("already following")
	}
	return data_access.FollowUser(userId, followerId)
}
